(function(){

	/**
	 * 静态资源管理器
	 */
	
	class StaticResourcesUtil {
		constructor(){
			//已经加载的图片数量，默认0
			this.alreadyLoadNum = 0;

			//已经加载的图片资源
			this.loadedImages = {};
		}

		loadImages(jsonUrl,callback){
			var _this = this;
			fetch(jsonUrl)
				.then(res=>res.json())
				.then(data=>{
					let imageArr = data.images;
					imageArr.forEach((imgObj,index)=>{
						let image = new Image();
						image.index = index;
						image.src = imgObj.src;
						image.onload = function(){
							_this.alreadyLoadNum++;
							_this.loadedImages[imageArr[this.index].name] = this;
							callback && callback(_this.alreadyLoadNum,imageArr.length,_this.loadedImages);
						}
					})

				})
				.catch(err=>console.log(err));

		}
	}

	window.StaticResourcesUtil = StaticResourcesUtil;
})();
